home *** CD-ROM | disk | FTP | other *** search
- // TRACK.CPP - Race Course definition
- // by Mitchell E. Timin, State College, PA
- // see CAR.H & TRACK.H for class and structure declarations
- // This version is for Borland C++, version 3.1, and is for DOS
- // This is part of version 0.39 of RARS (Robot Auto Racing Simulation)
- // ver. 0.1 release January 12, 1995
- // ver. 0.2 1/23/95
- // ver. 0.3 2/7/95
- // ver. 0.39 3/6/95
- // March 9 - build_track() changed to automatically handle degrees or radians
-
- #include <fstream.h>
- #include <stdlib.h>
- #include "track.h"
- #include "gi.h" // needed only for resume_text_display()
-
- // array for track data file name:
- char trackfile[60];
-
- int NSEG; // number of track segments (see drawpath() in GRAPHICS.CPP)
- double X_MAX, Y_MAX; // maximum values that display must show, feet
- double width; // width of track, feet
- double TRK_STRT_X; // coordinates of where to start drawing track
- double TRK_STRT_Y; // (feet)
- double SCORE_BOARD_X; // These are in feet, track coordinates
- double SCORE_BOARD_Y; // (where the scoreboard is located)
- double LDR_BRD_X; // upper left corner of leader board, feet
- double LDR_BRD_Y;
- double LOTIX, LOTIY; // coords of start of "Length of track is ......"
- double FINISH; // fraction of segment 0 prior to finish line
- double from_start_to_seg1; // distance from start/finish line to end of segment
-
- // These two arrays describe the outer and inner boundaries of the track:
- segment *trackout;
- segment *trackin; // Note that the only difference between trackin and
- // trackout is a "width" feet smaller radius on the curves.
-
- // Reads the track definition file and builds the trackin and trackout
- // arrays. If the arc length of the first curve is < 5.0 the units are
- // assumed to be radians. Otherwise they are assumed to be degrees.
- void build_track()
- {
- ifstream inf(trackfile);
- static int degrees = -1; // will become 1 for degrees, 0 for radians
- int i;
-
- if(!inf) { // If a filename with no extension was entered,
- for(i=0; i<8; i++) { // append .trk and see if that works:
- if(trackfile[i] == '\0')
- break;
- if(trackfile[i] == '.')
- if(trackfile[i+1] == '\0')
- break;
- else {
- resume_normal_display();
- cout << "There is no track data file. :(" << endl;
- exit(1);
- }
- }
- trackfile[i++] = '.';
- trackfile[i++] = 't';
- trackfile[i++] = 'r';
- trackfile[i++] = 'k';
- trackfile[i] = '\0';
- inf.open(trackfile);
- if(!inf) {
- resume_normal_display();
- cout << "There is no track data file. :(" << endl;
- exit(1);
- }
- }
-
- inf >> NSEG >> X_MAX >> Y_MAX >> width;
- inf >> TRK_STRT_X >> TRK_STRT_Y;
- inf >> SCORE_BOARD_X >> SCORE_BOARD_Y;
- inf >> LDR_BRD_X >> LDR_BRD_Y;
- inf >> LOTIX >> LOTIY;
- inf >> FINISH;
- trackout = new segment[NSEG];
- trackin = new segment[NSEG];
-
- for(i=0; i<NSEG; i++) {
- inf >> trackout[i].radius >> trackout[i].length;
- if(degrees == -1 && trackout[i].radius != 0.0)
- if(trackout[i].length < 5.0)
- degrees = 0;
- else
- degrees = 1;
- if(degrees == 1 && trackout[i].radius != 0.0)
- trackout[i].length /= DEGPRAD;
- }
-
- for(i=0; i<NSEG; i++) {
- if(trackout[i].radius == 0.0)
- trackin[i].radius = trackout[i].radius;
- else
- trackin[i].radius = trackout[i].radius - width;
- trackin[i].length = trackout[i].length;
- }
- // initialize this global variable:
- from_start_to_seg1 = (1.0 - FINISH) * trackout[0].length;
- }
-